package hernanbosqued.parking;

import android.location.Location;

public class EntityParking implements Comparable<EntityParking>
{
	private final static int POS_NOMBRE  			  = 0;
	private final static int POS_LATITUD 			  = 1;
	private final static int POS_LONGITUD 			  = 2;
	private final static int POS_COCHERAS_TOTALES 	  = 3;
	private final static int POS_COCHERAS_DISPONIBLES = 4;
	private final static int POS_PRECIO_HORA		  = 5;

	public String	nombre;
	public double	latitud;
	public double	longitud;
	public double	cocheras_totales;
	public double	cocheras_disponibles;
	public String	precio_hora;
	public double	distancia;
	
	private EntityParking()
	{
		
	}
	
	public static EntityParking getInstance( Object[] p_param )
	{
		EntityParking response = new EntityParking(  );
		
		response.nombre 			  = (String) p_param[POS_NOMBRE];
		response.latitud			  = (Double) p_param[POS_LATITUD];
		response.longitud             = (Double) p_param[POS_LONGITUD];
		response.cocheras_totales     = (Double) p_param[POS_COCHERAS_TOTALES];
		response.cocheras_disponibles = (Double) p_param[POS_COCHERAS_DISPONIBLES];
		response.precio_hora		  = (String) p_param[POS_PRECIO_HORA];
				
		return response;
	}
	
	public void setDistance( Location p_location )
	{
		if( p_location != null )
		{
			final Location location 	  = new Location("PARKING_PROVIDER");
			location.setLatitude ( latitud  );
			location.setLongitude( longitud );	
			distancia = p_location.distanceTo( location );
		}
		else
		{ 
			distancia = -1;
		}
	}

	@Override
	public int compareTo( EntityParking another )
	{
		if( distancia > another.distancia )
		{
			return 1;
		}
		else if ( distancia < another.distancia )
		{
			return -1;
		}
		else return 0;		
	}
}
